package com.qilin.hscs.controller;

import com.aliyuncs.exceptions.ClientException;
import com.qilin.hscs.service.SMSService;
import com.qilin.hscs.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by 10188 on 2018/5/2.
 */
@RestController
@RequestMapping("/sms")
public class ValidationController {

    @Autowired
    private SMSService smsService;

    @PostMapping("/getVerificationCode")
    public ResultVO getVerificationCode(String phone) {
        try {
            return smsService.send(phone);
        } catch (ClientException e) {
            e.printStackTrace();
        }
        return null;
    }

    @PostMapping("/verify")
    public ResultVO verify(String phone, String code) {
        return smsService.verify(phone, code);
    }
}
